package com.edu.bhu.admin.util;

import com.edu.bhu.admin.domain.HouRecord;
import com.edu.bhu.common.utils.DateUtils;

import java.util.Date;

/**
 * @author zhangkeyi
 *
 * @desc rentStatus属性值工具类
 * @date 2022/3/03
 */
public class rentStatusUtil {

    //rentStatus常量
    public static final Long NORMAL_LOAN = 1L;//正常出租
    public static final Long OVERDUE_NORETURN = 2L;//逾期未退房
    public static final Long NORMAL_RETURN = 3L;//已退房

    //赋予HouRecord中的rentStatus属性值
    public static HouRecord changeStatus(HouRecord houRecord)
    {
        Date preReturnTime = houRecord.getEndTime();//预期退房时间
        Date today = DateUtils.getNowDate();//当前时间

        //判断是否已退房，如果未退房走此方法
        if(houRecord.getStatus() == 1)
        {
            //判断是否逾期
            if(Integer.valueOf(DateUtils.getDatePoorDays(today,preReturnTime)) > 0){
                houRecord.setRentStatus(OVERDUE_NORETURN);
            } else {
                houRecord.setRentStatus(NORMAL_LOAN);
            }
        } else if(houRecord.getStatus() == 2){
                houRecord.setRentStatus(NORMAL_RETURN);
        }

        return houRecord;
    }


}
